import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import vueJsx from "@vitejs/plugin-vue-jsx";
import path from "path";
import "./src/types/global.d.ts";
import vitePluginCompression from "vite-plugin-compression";
const vitePluginCompressionOptions: CompressionOptions = {
    verbose: true, // 是否在控制台中输出压缩结果
    disable: false,
    threshold: 10240, // 如果体积大于阈值将被压缩
    algorithm: "gzip", // 压缩算法
    ext: ".gz",
    deleteOriginFile: false, // 源文件压缩后是否删除
};
export default defineConfig({
    plugins: [
        vue(),
        AutoImport({
            imports: ["vue"],
            dts: "src/auto-import.d.ts", // 生成声明文件以及生成的文件路径
        }),
        vueJsx(),
        vitePluginCompression(vitePluginCompressionOptions),
    ],
    resolve: {
        alias: {
            "@": path.resolve(__dirname, "src"),
        },
    },
    server: {
        port: 18081,
        proxy: {
            "/api": {
                // target: "http://localhost:3001/",
                target: "http:47.100.62.134:3001/",
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, ""),
            },
        },
    },
    build: {
        outDir: "dist",
        assetsDir: "static",
        sourcemap: false,
        minify: "terser", // 启用terser压缩 需安装才行

        terserOptions: {
            compress: {
                // drop_console: true,
                // drop_debugger: true,
            },
        },
        rollupOptions: {
            output: {
                chunkFileNames: "static/js/[name]-[hash].js",
                entryFileNames: "static/js/[name]-[hash].js",
                assetFileNames: "static/[ext]/[name]-[hash].[ext]",
            },
            plugins: [],
        },
    },
});
